var tbody = document.querySelector('tbody')
var btn1 = document.querySelector('.btn1')
var search = document.querySelector('.search')
console.log(btn1);
btn1.onclick = ()=>{
    axios.get('/api/search',{params:{ searchkey:search.value }}).then((res)=>{
        renderlist(res.data.list)
        console.log(res.data);
    })
}





function renderlist(data){
    var str = ``
data.forEach((item) => {
    str +=`<tr>
    <td>${item.num1}</td>
    <td>${item.gangwei}</td>
    <td>${item.name}</td>
    <td>${item.num2}</td>
    <td class="${item.status?'zc':'yc'}">${item.status?'正常':'异常'}</td>
    <td>${item.time}</td>
    <td>
    <em style="cursor: pointer;" class="iconfont icon-bianji"></em>
    <em style="cursor: pointer;" class="iconfont icon-shanchu" data-name="${item.name}"></em>
    <td>
</tr>
    `
});
if(str == ''){
    tbody.innerHTML = '<ul style="text-align:center;color:red">未查询到数据!</ul>'
}
tbody.innerHTML = str
}

//删除
tbody.onclick = (e)=>{
    if(e.target.tagName == 'EM'&&e.target.classList.contains('icon-shanchu')){
        axios.post('/api/delete',{name:e.target.dataset.name}).then((res)=>{
            console.log(res);
            renderlist(res.data.list)
        })
    }

}

axios.get('/api/list',{params:{page:1,count:4}}).then((res)=>{
    renderlist(res.data.list)
    console.log(res.data.list);
})

var shang = document.querySelector('.shang')
var xia = document.querySelector('.xia')
var kuang = document.querySelector('.kuang')

shang.onclick = ()=>{

    kuang.innerHTML = kuang.innerHTML--
}
xia.onclick = ()=>{
    
    kuang.innerHTML = kuang.innerHTML++
}